//logs.js
var app = getApp(),
  config = require("../../config/card.config.js"),
  productNavFooter = config.green.footernav.shopping.nav_footer,
  productFooterNav = config.green.footernav.shopping.footer_nav,
  inputComment = "",
  commentIndex,
  defaultlogo = "https://resource.aijiatui.com/ai-img/img/defaultlogo.png",
  companyLogo = "https://resource.aijiatui.com/background/LOGO50_5020180327.png",
  screenHeight = void 0;

Page({
  data: {
    nav_footer_active: 0,
    isShowRobotTip: false,
    shopMask:false,
    showChoose:false,
   
    card_detail: {
      isIphoneX: app.globalData.isIphoneXX,
      userInfo: '',
      winHeight: 0,
      open_card_detail: false,
      card: {
        thumbs_num: 0,
        template_type: 3,
        browse_headimg_num: 1,
        item: '',
        weixinid: "13052383227",
        browse_headimgs: []
      },
      noReadList:{
        card_logo:'../../source/image/avater.jpg',
        card_name:'大米科技有限公司',
        content:'张三李四王二麻子'
      }
    },
    business: {
      isIphoneX: app.globalData.isIphoneXX,
      downTips: ["我也是有底线的", "下面什么都没有呢", "客官，不能再拉了"],
      scrollTop: 100,
      scrollHeight: 200,
      productNum: 0,
      winHeight: 0,
      headImageUrl: 'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1539768807733&di=b33663d6448cef9efc74d57dfba013bd&imgtype=0&src=http%3A%2F%2Fpic.90sjimg.com%2Fback_pic%2F00%2F00%2F40%2F82%2F4db824aaf9f925a275d7146291fe8446.jpg',
      shoppingName: '大米科技',
      buytip: false,
      userRedPoint: false,
      company_logo: '../../source/image/avater.jpg',
      topInitialOpacity: 1,
      // couponList:[
      //   { 
      //     status : 0,
      //     discount: 7,
      //     userCouponCountLimit:10,
      //     applyScopeType: 0,
      //   },{
      //     status: 1,
      //     discount: 7,
      //     userCouponCountLimit: 10,
      //     applyScopeType: 1,
      //   }
      // ],
      currenttitles: 'aaaa',
      // showClassify:true,
      titles: [{
          classifyName: '全部商品',
        },
        {
          classifyName: '手机数码',
        },
        {
          classifyName: '家用电器',
        },
        {
          classifyName: '热门',
        },
        {
          classifyName: '男装',
        },
        {
          classifyName: '鞋包'
        }
      ],
      titlescurrent: {
        classifyName: '全部商品',
      },
      list: []

    },
    dynamic_list: {
      isIphoneX: app.globalData.isIphoneXX,
      downTips: ["我也是有底线的", "下面什么都没有呢", "客官，不能再拉了"],
      winHeight: 800,
      hassharestatus: true,
      isSendLike: false,
      android: false,
      commentconfig: 0, //0的时候只有赞，1的时候有评论
      list: [{
          type: 1,
          dynamic_id: 0, //评论点赞集合中的角标
          card_name: '丁伟',
          fristImg: '../../source/image/avater.jpg',
          title_txt: 'title_txt',
          card_logo: '../../source/image/avater.jpg',
          dynamic_comment: [
            // {
            //   content: '张三李四王二麻子',
            //   type: 0,
            // },
            {
              type: 1,
              content: [
                '../../source/image/avater.jpg',
                '../../source/image/avater.jpg',
                '../../source/image/avater.jpg',
                '../../source/image/avater.jpg',
                '../../source/image/avater.jpg',
              ],
            },
            // {
            //   type: 1,
            //   content: [
            //     '../../source/image/avater.jpg',
            //   ],
            // },

          ],
          display_time: '2018-10-20'
        },
        {
          type: 0,
          card_logo: '../../source/image/avater.jpg',
          dynamic_id: 1,
          card_name: '哈哈哈',
          fristImg: '../../source/image/avater.jpg',
          company_profile: '大米科技',
          title_txt: '大米科技成功上市撒打算打算打算打算啊实打实的啊',
          pub_time: '2019-10-10',
          dynamic_comment: [


          ],
          display_time: '2018-10-20'
        }
      ],
      open: [
        false,
        false
      ],

      comments: [
        [{
            card_name: '丁伟',
            comment_content: '你说的是啥啊'
          },
          {
            card_name: '朱伟',
            comment_content: '你说的是啥啊'
          }
        ],
        [{
            card_name: '王江',
            comment_content: '你说的是啥啊'
          },
          {
            card_name: '王江',
            comment_content: '你说的是啥啊'
          }
        ],
      ],
      thumbsList: [
        [{
            card_name: '丁伟',
          },
          {
            card_name: '朱伟',
          }
        ],
        [{
            card_name: '王江',
          },

        ],

      ],

      open_input: false, //是否显示tabbar
      text_area: '',
    },
    main: {
      isIphoneX: app.globalData.isIphoneXX,
      winHeight: 800,
      img1: "../../source/image/avater.jpg",
      img2: "../../source/image/avater.jpg",
      show_sm_box: true,
      compandy_addr: "上海宝山",
      color: "rgba(255,255,255,0.8)",
      select_color: "#fff",
      img_urls: [""],
      card_id: "",
      auto_play: true,
      nodata: false,
      main: [{
          type: 16, //顶部空一个高度
          content: {
            height: 100,
          }
        },
        {
          type: 13, //视频播放
          content: {
            url: 'http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4',
            auto_play: true,
            img: "../../source/image/avater.jpg",
            showFontType: 2,
          }
        },
        {
          type: 9, //只有一个标题
          name: "只有一个标题",

        },
        {
          type: 17,
          content: {
            showType: 2,
            text: '什么玩意',
            link: 'www.baidu.com',
            appId: '112',
            height: 100,
            img: ["../../source/image/avater.jpg"],
            showFontType: 2,
          }
        },
        {
          type: 0, //广告位
          content: [
            "../../source/image/avater.jpg",
            "../../source/image/avater.jpg",
            "../../source/image/avater.jpg"
          ],
          imgType: 1
        },
        {
          type: 1, //公司介绍
          showFontType: 2,
          name: '大米科技',
          content: [{
            company_info: '大米科技生产大米'
          }]
        },
        {
          type: 25, //资讯
          name: '资讯',
          showFontType: 2,
          content: [{
              head_img: '../../source/image/avater.jpg',
              title: '大米科技已经在2018年10月成功纳斯达克成功上市',
              url: 'https://www.baidu.com',
              time: '2019.10.10'
            },
            {
              head_img: '../../source/image/avater.jpg',
              title: '大米科技已经在2018年10月成功纳斯达克成功上市',
              url: 'https://www.pingan.com',
              time: '2019.10.10'
            }

          ]
        },
        {
          type: 15,
          showFontType: 2,
          content: {
            phone: '021-10086',
            title: '联系方式'
          }
        },
        {
          type: 5, //横向的三张图
          showFontType: 2,
          name: '横向的三张图',
          content: [
            "../../source/image/avater.jpg",
            "../../source/image/avater.jpg",
            "../../source/image/avater.jpg"
          ]
        },
        {
          type: 6,
          showFontType: 2,
          name: '招聘',
          content: [{
              cp_recruitment_name: 'android 工程师',
              cp_salary: '面议',
              cp_bussiness_life: '1-5年工作经验',
              education: '本科以及以上'
            },
            {
              cp_recruitment_name: 'ios 工程师',
              cp_salary: '面议',
              cp_bussiness_life: '1-5年工作经验',
              education: '本科以及以上'
            }
          ]

        },
        {
          type: 8,
          name: '公司地址',
          showFontType: 2,
          content: [{
            company_addr: '上海宝山区上海大学'
          }]
        },
        {
          type: 7, //团队介绍的一种风格
          showFontType: 2,
          name: '团队介绍',
          content: [{
            card_id: '1212',
            card_logo: '../../source/image/avater.jpg',
            card_name: '张三',
            role_name: '总监',
            card_show_tel: '13052383327',
            card_email: '314097203@qq.com'
          }]
        },
        {
          type: 4, //团队介绍的一种风格
          showFontType: 2,
          name: '团队介绍',
          content: [{
              head_img: '../../source/image/avater.jpg',
              name: '王江',
              job: '董事长',
              text: '毕业于麻省理工大学的博士，对人工智能有深入研究。 目前为Google的首席科学家',
              id: '1221'
            },
            {
              head_img: '../../source/image/avater.jpg',
              name: '朱伟',
              job: '总经理',
              text: '毕业于麻省理工大学的博士，对人工智能有深入研究。 目前为Google的首席科学家的小弟',
              id: '1221'
            }
          ]
        },
        {
          type: 3,
          showFontType: 2,
          name: '相册',
          content: [{
              c_album_title: '公司团队',
              num: '10',
              c_album_id: '1221',
              pic_url: '../../source/image/avater.jpg'
            },
            {
              c_album_title: '办公环境',
              num: '15',
              c_album_id: '1221',
              pic_url: '../../source/image/avater.jpg'
            },
          ]
        },
        {
          type: 27, //只有文字没有标题
          content: [
            '哈哈哈', '呵呵', '嘻嘻'
          ]
        },
        {
          type: 10, //图片展示
          showFontType: 2,
          // content: {  //data 大于0是 标题加多张图
          //   title:"照片",
          //   data:[
          //     {
          //     img_url:'../../source/image/avater.jpg'
          //     },
          //     {
          //       img_url: '../../source/image/avater.jpg'
          //     },
          //     {
          //       img_url: '../../source/image/avater.jpg'
          //     },
          //   ],
          // },
          //content.data大于0时

          //判断imgType 1，2，3，4
          // imgType: 1,  //没有标题一张图
          // content: [
          //    '../../source/image/avater.jpg'

          // ],

          // imgType: 2,//横向的没有标题多张图  最少三张
          // content: [
          //   '../../source/image/avater.jpg',
          //   '../../source/image/avater.jpg',
          //   '../../source/image/avater.jpg',
          // ],

          // imgType: 3,//3张图， 左边一张右边两张
          // content: [
          //   '../../source/image/avater.jpg',
          //   '../../source/image/avater.jpg',
          //   '../../source/image/avater.jpg',
          // ],

          imgType: 4, //有边距的多张图
          content: [
            '../../source/image/avater.jpg',
            '../../source/image/avater.jpg',
          ],
        },
        {
          type: 26, //图文混排 文字在图片上
          imgType: 1, //1，2，3，4
          fontType: 2,
          showFontType: 2,
          fontTypeContent: [{
            showTextType: '1',
            mainTitle: "这个不知道填啥",
            secondTitle: "副标题",
            depc: "描述",
            text: "标题" //fontType ==2时使用
          }],
          content: [ //必须要有图
            '../../source/image/avater.jpg',
            '../../source/image/avater.jpg',
            '../../source/image/avater.jpg',
          ],



        },





      ],
      display_top_img: !0
    },
  },

  showShopPoster: function () {
    this.setData({
      shopMask: true,
      showChoose: true,
    });
  },

  hideShopMask: function () {
    wx.hideLoading(),
      this.setData({
        shopMask: false,
        "card_detail.choose_product": false,
      "card_detail.savePoster": false,
      "card_detail.showFriend": false,
      saveShopBtn: false,
      showCanvas: false,
      showFriendCanvas: false,
        posterList: []
      });
  },

  open_card_detail: function() {
    var that = this,
      open_card_detail = that.data.card_detail.open_card_detail;
    open_card_detail = !open_card_detail,
      that.setData({
        "card_detail.open_card_detail": open_card_detail
      });
  },

  goDynamicDetail: function(e) {
    // if (1 != this.data.noClick) {
    //   this.setData({
    //     noClick: !0
    //   });
    //   var that = this,
    //     t = e.currentTarget.dataset.id,
    //     n = that.data.dynamic_list.list[t].dynamic_id;
    //   wx.navigateTo({
    //     url: "/pages/web_view/web_view?send_name1=" + d.getusersync().nickname + "&share_name=" +        that.data.card_detail.card.simple.card_name + "&card_id=" + D + "&dyId=" + n + "&identify=" + i + "&type=2"
    //   });
    // }
  },


  go_dynamic: function(e) {
    var url = e.currentTarget.dataset.dynamic_id;
    console.log(url),
      wx.navigateTo({
        url: "/pages/web_view/web_view?url=" + url
      });
  },

  call_phone: function(e) {
    var a = e.currentTarget.dataset.tel;
    wx.makePhoneCall({
      phoneNumber: a
    })
  },


  _goback: function() {
    wx.redirectTo({
      url: "/pages/index/index"
    });
  },

  change_footer_name: function(e) {
    var index = e.currentTarget.dataset.name;
    this.setData({
      nav_footer_active: index,
    })

    wx.setNavigationBarTitle({
      title: productFooterNav[index]
    })
  },

  from_send: function(e) {
    var a = e.detail.formId;
    console.log(e)
    // d.sendFormId(a, function (e) { });
    this.requestSendMessage(a)
  },

  gaveZan: function() {
    var that = this;
    if (that.data.card_detail.showZan) {
      var zan = 1 * that.data.card_detail.card.thumbs_num - 1;
      wx.removeStorage({
          key: "zan" + app.globalData.itemInfo.CardId,
          success: function(e) {}
        }),
        that.setData({
          "card_detail.showZan": false,
          "card_detail.card.thumbs_num": zan
        })
      that.requestSetZan(0); //0是取消赞

    } else {
      var num = 1 * that.data.card_detail.card.thumbs_num + 1;
      wx.setStorageSync("zan" + app.globalData.itemInfo.CardId, !0),
        that.setData({
          "card_detail.showZan": true,
          "card_detail.card.thumbs_num": num
        })
      that.requestSetZan(1); //1赞
    }
    that.setData({
        "card_detail.zanok": true
      }),
      setTimeout(function() {
        that.setData({
          "card_detail.zanok": !1
        });
      }, 500);
  },

  onLoad: function(options) {
    console.log(options)
    if (options != null && options != undefined &&
      options.sharetype != null && options.sharetype > 0) {
      app.globalData.itemInfo = JSON.parse(options.itemInfo);

      console.log(options.itemInfo);
      this.requestAddCard(options.msg);
    }
    
    this.getWinHeight();

    if (app.globalData.isLogin) {
      this.initData();
    }
      
  },


  initData: function(){
    var that = this;
    that.setData({
      "card_detail.card.item": app.globalData.itemInfo,
      product_show: 0,
      "card_detail.product_show": 1,
      nav_footer: productNavFooter,
      "business.business_show_type": 1,
      "card_detail.userInfo": app.globalData.userInfo
    }),
      wx.setNavigationBarTitle({
        title: productFooterNav[that.data.nav_footer_active]
      }),

      console.log('this.data.userInfo');
    console.log(this.data.card_detail.userInfo);

    that.requestBrowse();
    that.requestZanAndBrowse();

    if (app.globalData.itemInfo.StoreId == null || app.globalData.itemInfo.StoreId == undefined || app.globalData.itemInfo.StoreId == '') {
      that.setData({
        "dynamic_list.open_input": true
      })
    } else {
      that.requestShoppingInfo(),
        that.requestCircle(),
        that.requestCompanyWeb()
    }
  },

  login: function () {
    this.initData();
  },

  _gotoUserCenter:function(e){
    wx.navigateTo({
      url: "/pages/user_info/user_info",
    });
  },

  card_options: function(e) {
    var that = this,
      content = e.currentTarget.dataset.target;
    switch (e.currentTarget.dataset.option) {
      case "call":
        wx.makePhoneCall({
          phoneNumber: content,
        })
        break;

      case "call1":
        wx.makePhoneCall({
          phoneNumber: content,
        })
        break;

      case "copy":
        wx.setClipboardData({
          data: content,
          success: function(res) {

          }
        })
        break;

      case "company":
        console.log('company')
        break;

      case "company_addr":
        console.log('company_addr')
        break;
    }
  },

  addPhoneContact: function() {
    var that = this,
      card_detail = that.data.card_detail;
    wx.addPhoneContact({
        firstName: card_detail.card.item.Name,
        mobilePhoneNumber: card_detail.card.item.Tel || "",
        weChatNumber: card_detail.card.item.Tel || "",
        organization: card_detail.card.item.CompanyName || "",
        title: card_detail.card.item.Job,
        workAddressStreet: "" + card_detail.card.item.Address || "",
        email: card_detail.card.item.Email || "",
        success: function() {

        }
      }),
      that.setData({
        isIntroduction: false
      });
  },

  bindtitles: function(e) {
    var that = this,
      titlesindex = e.currentTarget.dataset.titlesindex,
      code = e.currentTarget.dataset.code;
    wx.setStorageSync("titlescurrent", titlesindex),
      wx.setStorageSync("classifyCode", code),
      that.setData({
        "business.titlescurrent": titlesindex,
        "business.currenttitles": "a" + parseInt(titlesindex - 1),
        classifyCode: code
      })
    that.requestGetProductList(code)
  },

  onShareAppMessage: function (res) {
    if (res.from === 'button') {
      // 来自页面内转发按钮
      console.log(res.target)
    }
    return {
      title: this.data.card_detail.card.item.Name +'的名片',
      path: 'pages/personal/personal?sharetype=1&itemInfo=' + JSON.stringify(app.globalData.itemInfo) + '&msg=通过' + app.globalData.userInfo.Name+'分享'
    }
  },

  requestSetZan: function(State) {
    var that = this;
    wx.request({
      url: app.globalData.url + "CardLike",
      header: {
        'content-type': 'application/x-www-form-urlencoded' //默认值
      },
      data: {
        "CardUserId": app.globalData.itemInfo.Id,
        "UserId": app.globalData.userInfo.Id,
        "State": State
      },
      method: 'GET',
      success: function(res) {
        console.log("requestSetZan ======");
        console.log(res.data);
      }
    })

  },

  requestBrowse: function() {
    var that = this;
    wx.request({
      url: app.globalData.url + "CardBrowse",
      header: {
        'content-type': 'application/x-www-form-urlencoded' //默认值
      },
      data: {
        "CardUserId": app.globalData.itemInfo.Id,
        "UserId": app.globalData.userInfo.Id,
      },
      method: 'GET',
      success: function(res) {
        console.log("requestBrowse ======");
        console.log(res.data);
      }
    })
  },

  requestZanAndBrowse: function() {
    var that = this;
    console.log("requestZanAndBrowse" + app.globalData.userInfo.Id)
    wx.request({
      url: app.globalData.url + "CardMark",
      header: {
        'content-type': 'application/x-www-form-urlencoded' //默认值
      },
      data: {
        "CardUserId": app.globalData.itemInfo.Id,
        "UserId": app.globalData.userInfo.Id,
      },

      method: 'GET',
      success: function(res) {
        console.log("requestZanAndBrowse ======");
        console.log(res.data);
        if (res.data.Code == 1) {
          that.setData({
            "card_detail.showZan": res.data.ResultObject.Likeed == 1 ? true : false,
            "card_detail.card.thumbs_num": res.data.ResultObject.LikeNum,
            "card_detail.card.browse_headimg_num": res.data.ResultObject.BrowseNum,
            "card_detail.card.browse_headimgs": res.data.ResultObject.AvaterUrl
          });
        }
      }
    })
  },

  requestShoppingInfo: function() {
    var that = this;

    wx.request({
      url: app.globalData.url + "GetShopInfo",
      header: {
        'content-type': 'application/x-www-form-urlencoded' //默认值
      },
      data: {
        "StoreId": app.globalData.itemInfo.StoreId,
      },
      method: 'GET',
      success: function(res) {
        console.log("requestShoppingInfo ======");
        console.log(res.data);
        that.setData({
          business: res.data.ResultObject,
          "business.isIphoneX": app.globalData.isIphoneXX,
          "business.winHeight": screenHeight,
          "business.titlescurrent": 0,
          "business.currenttitles": "a" + parseInt(0),
        });

        that.requestGetProductList(null);
      },

    })
  },

  requestGetProductList: function(CategoryId) {
    var that = this;
    wx.request({
      url: app.globalData.url + "GetProductList",
      header: {
        'content-type': 'application/x-www-form-urlencoded' //默认值
      },
      data: {
        "StoreId": app.globalData.itemInfo.StoreId,
        "CategoryId": CategoryId == null ? "" : CategoryId,
        "Index": 0,
      },
      method: 'GET',
      success: function(res) {
        console.log("requestGetProductList ======");
        console.log(res.data);

        that.setData({
          "business.list": res.data.ResultObject,
         
        });
      }
    })
  },


  requestSendMessage: function(FormId) {
    var that = this;
    
    wx.request({
      url: app.globalData.url + "SendMessage",
      header: {
        'content-type': 'application/x-www-form-urlencoded' //默认值
      },
      data: {
        "FormId": FormId,
        "Page": '',
        "OpenId": app.globalData.itemInfo.MPOpenId,
        "Data": '王江在访问商城',
      },
      method: 'GET',
      success: function(res) {
        console.log("requestSendMessage ======");
        console.log(app.globalData.itemInfo);

      }
    })
  },

  requestCircle: function() {
    var that = this;
    wx.request({
      url: app.globalData.url + "GetCircle",
      header: {
        'content-type': 'application/x-www-form-urlencoded' //默认值
      },
      data: {
        "StoreId": app.globalData.itemInfo.StoreId,
        "UserId": app.globalData.userInfo.Id,
      },
      method: 'GET',
      success: function(res) {
        console.log("requestCircle ======");
        console.log(res.data);
        that.setData({
          dynamic_list: res.data.ResultObject,
          "dynamic_list.isIphoneX": app.globalData.isIphoneXX,
        })
      }
    })
  },

  gochatDetail: function() {

    wx.navigateTo({
      url: "/pages/chat_detail/chat_detail?card_id=" + app.globalData.itemInfo.Id + "&head_img=" + app.globalData.itemInfo.AvatarUrl
    });
  },

  chat_go: function() {

  },

  openZan: function(e) {
    var index = e.currentTarget.dataset.index,
      that = this,
      open = new Array;
    open[index] = true,
      that.setData({
        "dynamic_list.open": open,
        "dynamic_list.open_input": false
      });
  },


  closed: function() {

    if (this.data.dynamic_list.open) {
      for (var that = this, _open = that.data.dynamic_list.open, t = 0; t < _open.length; t++) _open[t] = false;
      that.setData({
        "dynamic_list.open": _open,
        "dynamic_list.open_input": false
      });
    }
  },

  closed_dynamic: function(e) {
    console.log('closed_dynamic')

    for (var that = this, _open = app.data.dynamic_list.open, n = 0; n < _open.length; n++) _open[n] = false;
    that.setData({
      "dynamic_list.open": _open,
      "dynamic_list.open_input": false
    });
  },

  sendComment: function() {
    var that = this;
    console.log('sendComment');
    if (inputComment.length < 1) that.setData({
      "dynamic_list.open_input": false
    });
    else {
      var _messageId = that.data.dynamic_list.list[commentIndex].MessageId,
        _commentsList = that.data.dynamic_list.comments,
        that = this;
      console.log(inputComment);
      wx.request({
        url: app.globalData.url + "CommentCircle",
        header: {
          'content-type': 'application/x-www-form-urlencoded' //默认值
        },
        data: {
          "MessageId": _messageId,
          "UserId": app.globalData.userInfo.Id,
          "Comment": inputComment,
        },
        method: 'GET',
        success: function (res) {
          console.log(res.data)
          if (res.data.Code == 1){
            var item = new Object;
            item.card_name = app.globalData.userInfo.Name;
            item.comment_content = inputComment;
            item.UserId = app.globalData.userInfo.Id;
            item.commentId = res.data.ResultObject.CommentID;
            _commentsList[commentIndex].push(item)

            var newCommentsList = _commentsList;
            that.setData({
              "dynamic_list.comments": newCommentsList,
            });
            that.closed();
          } else {

          }
        }
      })
    }
  },

  getVal: function(e) {
    inputComment = e.detail.value;
  },

  sendLike: function(e) {

    var that = this,
      _index = e.currentTarget.dataset.index,
      _messageId = that.data.dynamic_list.list[_index].MessageId,
      _likeState = that.data.dynamic_list.list[_index].LikeState,
      _requestState,
      _thumbsList = that.data.dynamic_list.thumbsList;
    console.log('LikeState')
    console.log(_likeState)
    if (_likeState == 0) {
      _requestState = 1;
    } else if (_likeState == 1) {
      _requestState = 0;
    }
    this.setData({
      "dynamic_list.isSendLike": true
    })
    wx.request({
      url: app.globalData.url + "LikeCircle",
      header: {
        'content-type': 'application/x-www-form-urlencoded' //默认值
      },
      data: {
        "MessageId": _messageId,
        "UserId": app.globalData.userInfo.Id,
        "State": _requestState,
      },
      method: 'GET',
      success: function(res) {

        console.log(res.data);

        if (res.data.Code == 1) {
          console.log("sendLike ======");

          if (_likeState == 0) {
            var item = new Object;
            item.card_name = app.globalData.userInfo.Name;
            item.UserId = app.globalData.userInfo.Id;
            if (_thumbsList.length == 0) {
              console.log("===== 0 ======")
              _thumbsList = new Array(_index);
            }

            if (_thumbsList[_index]) {
              _thumbsList[_index].push(item);
            } else {
              let itemArray = new Array();
              itemArray.push(item);
              _thumbsList.splice(_index, 0, itemArray)
            }
            _likeState = 1
            
          } else if (_likeState == 1) {
            console.log(_thumbsList);
        
            let newlist = _thumbsList[_index].filter(function(thumbs, index) {
              return app.globalData.userInfo.Id != thumbs.UserId;
            });
            _likeState = 0
            console.log(_thumbsList[_index])

            _thumbsList.splice(_index, 1, newlist)
          }


         let newthumbsList = _thumbsList;
          var updateState = "dynamic_list.list[" + _index + "].LikeState"
          that.setData({
            "dynamic_list.thumbsList": newthumbsList,
            [updateState]: _likeState,
          });

        } else {

        }

      }
    })

  },

  sendLike: function(e) {

    var that = this,
      _index = e.currentTarget.dataset.index,
      _messageId = that.data.dynamic_list.list[_index].MessageId,
      _likeState = that.data.dynamic_list.list[_index].LikeState,
      _requestState,
      _thumbsList = that.data.dynamic_list.thumbsList;
    console.log('LikeState')
    console.log(_likeState)
    if (_likeState == 0) {
      _requestState = 1;
    } else if (_likeState == 1) {
      _requestState = 0;
    }
    this.setData({
      "dynamic_list.isSendLike": true
    })
    wx.request({
      url: app.globalData.url + "LikeCircle",
      header: {
        'content-type': 'application/x-www-form-urlencoded' //默认值
      },
      data: {
        "MessageId": _messageId,
        "UserId": app.globalData.userInfo.Id,
        "State": _requestState,
      },
      method: 'GET',
      success: function(res) {

        console.log(res.data);

        if (res.data.Code == 1) {
          console.log("sendLike ======");

          if (_likeState == 0) {
            var item = new Object;
            item.card_name = app.globalData.userInfo.Name;
            item.UserId = app.globalData.userInfo.Id;
            if (_thumbsList.length == 0) {
              console.log("===== 0 ======")
              _thumbsList = new Array(_index);
            }

            if (_thumbsList[_index]) {
              _thumbsList[_index].push(item);
            } else {
              let itemArray = new Array();
              itemArray.push(item);
              _thumbsList.splice(_index, 0, itemArray)
            }
            _likeState = 1
            
          } else if (_likeState == 1) {
            console.log(_thumbsList);
        
            let newlist = _thumbsList[_index].filter(function(thumbs, index) {
              return app.globalData.userInfo.Id != thumbs.UserId;
            });
            _likeState = 0
            console.log(_thumbsList[_index])

            _thumbsList.splice(_index, 1, newlist)
          }


         let newthumbsList = _thumbsList;
          var updateState = "dynamic_list.list[" + _index + "].LikeState"
          that.setData({
            "dynamic_list.thumbsList": newthumbsList,
            [updateState]: _likeState,
          });

        } else {

        }

      }
    })

  },

  dynamic_comment: function(e) {
    var that = this;
    commentIndex = e.currentTarget.dataset.index;
    that.data.dynamic_list.list[commentIndex].open = false,
    that.setData({
      "dynamic_list.open_input": true
    });
  },

  deletedComment: function(e){
    var that = this, 
   commentInfo =  e.currentTarget.dataset.index,
     commentList = that.data.dynamic_list.comments;
   if (commentInfo.UserId == app.globalData.userInfo.Id){
     wx.showActionSheet({
       itemList: ['删除'],
       itemColor:'#CD2626',
       success: function (res) {//res.tapIndex点击的列表项
         wx.request({
           url: app.globalData.url + "DelComment",
           header: {
             'content-type': 'application/x-www-form-urlencoded' //默认值
           },
           data: {
             "CommentId": commentInfo.commentId,
           },
           method: 'GET',
           success: function (res) {
            if (res.data.Code == 1){
              commentList.forEach(function (comments, indexs) {
                let newComments = comments.filter(function (comment, index) {
                  return comment.commentId != commentInfo.commentId;
                })
                commentList.splice(indexs, 1, newComments);
              })
              let newCommentList = commentList;
              that.setData({
                "dynamic_list.comments": newCommentList,
              });
            }
           }
          })
       },
     })
   }
  },

  requestCompanyWeb: function () {
    var that = this;
    wx.request({
      url: app.globalData.url + "GetCompanyWeb",
      header: {
        'content-type': 'application/x-www-form-urlencoded' //默认值
      },
      data: {
        "StoreId": app.globalData.itemInfo.StoreId,
      },
      method: 'GET',
      success: function (res) {
        console.log("requestCompanyWeb ======");
        console.log(res.data);
        if (res.data.Code == 1) {
          let CompanyWebData = new Array();
          CompanyWebData = res.data.ResultObject;
          console.log(CompanyWebData);
          if (CompanyWebData.main.length > 0){
            that.setData({
              main: CompanyWebData,
              "main.isIphoneX": app.globalData.isIphoneXX,
            })
          }
        }
        that.getWinHeight();
        
      }
    })
  },

  requestAddCard: function (msg) {
    var that = this;
    wx.request({
      url: app.globalData.url + "AddCard",
      header: {
        'content-type': 'application/x-www-form-urlencoded' //默认值
      },
      data: {
        "UserId": app.globalData.userInfo.Id,
        "LinkId": app.globalData.itemInfo.Id,
        "FromTip": msg
      },
      method: 'GET',
      success: function (res) {
       
      }
    })
  },

  dyanmic_card_logo: function (e) {
    var that = this,
      list = that.data.dynamic_list.list,
      index = e.target.dataset.index;
    1 == list[index].type ? list[index].card_logo = defaultlogo : list[index].card_logo = companyLogo,
      that.setData({
      "dynamic_list.list": list
      });
  },

  getWinHeight: function () {
    var that = this;
    wx.getSystemInfo({
      success: function (res) {
        screenHeight = res.windowHeight,
        console.log(screenHeight);
        that.setData({
        "card_detail.winHeight": screenHeight,
        "business.winHeight": screenHeight,
        "dynamic_list.winHeight": screenHeight,
        "main.winHeight": screenHeight
        });
      }
    });
  },

  setTopBannerStatus: function (e) {
    var that = this,
      t = 90;
    "undefined" != that.data.business.couponList && that.data.business.couponList.length > 0 && (t = 260);
    var n = Math.max(1 - e.detail.scrollTop / t, 0),
      i = Math.min(Math.max((e.detail.scrollTop - t) / t, 0), 1);
    this.setData({
      "business.scrollHeight": t - 40,
      "business.scrollTop": e.detail.scrollTop,
      "business.topInitialOpacity": n,
      "business.topOpacity": i
    });
  },

})